﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _2015.DivAdmin
{
    public partial class DivAdminMsg : System.Web.UI.Page
    {
        String Invite1;
        String Invite2;
        String Invite3;
        String Sender1;
        String Sender2;
        String Sender3;
        String Division1;
        String Division2;
        String Division3;
        String ImageUser1;
        String ImageUser2;
        String ImageUser3;
        protected void Page_Load(object sender, EventArgs e)
        {
            String Name = (String)Session["LoggingInfo"];
            String Position = (String)Session["LoggingPosition"];
            String username = (String)Session["LoggingInfoUsername"];
            LabelDivHeadName.Text = Name;
            LabelDivHeadPosition.Text = "(" + Position + ")";

            ImageProfile.ImageUrl = "../ProfilePicHandler.ashx?uname=" + username;


            string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand ReqCom3 = new SqlCommand("spNotifications", con);
                ReqCom3.CommandType = CommandType.StoredProcedure;

                SqlParameter ReqName3 = new SqlParameter("@username", username);
                ReqCom3.Parameters.Add(ReqName3);



                con.Open();
                SqlDataReader drreq3;

                drreq3 = ReqCom3.ExecuteReader();

                if (drreq3.Read())
                {
                    Invite1 = Convert.ToString(drreq3["REQUEST1"]);
                    Invite2 = Convert.ToString(drreq3["REQUEST2"]);
                    Invite3 = Convert.ToString(drreq3["REQUEST3"]);
                    Sender1 = Convert.ToString(drreq3["SENDER1"]);
                    Sender2 = Convert.ToString(drreq3["SENDER2"]);
                    Sender3 = Convert.ToString(drreq3["SENDER3"]);
                    Division1 = Convert.ToString(drreq3["DIVISION1"]);
                    Division2 = Convert.ToString(drreq3["DIVISION2"]);
                    Division3 = Convert.ToString(drreq3["DIVISION3"]);

                }
            }
            //////////////////////////////////////////Profile Image Extraction//////////////////////////////////
            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand ReqUser1 = new SqlCommand("spGetImageUser1", con);
                ReqUser1.CommandType = CommandType.StoredProcedure;

                SqlParameter ReqName3 = new SqlParameter("@name", Sender1);
                ReqUser1.Parameters.Add(ReqName3);



                con.Open();
                SqlDataReader drreq3;

                drreq3 = ReqUser1.ExecuteReader();

                if (drreq3.Read())
                {
                    ImageUser1 = Convert.ToString(drreq3["username"]);


                }
            }

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand ReqUser1 = new SqlCommand("spGetImageUser2", con);
                ReqUser1.CommandType = CommandType.StoredProcedure;

                SqlParameter ReqName3 = new SqlParameter("@name", Sender2);
                ReqUser1.Parameters.Add(ReqName3);



                con.Open();
                SqlDataReader drreq3;

                drreq3 = ReqUser1.ExecuteReader();

                if (drreq3.Read())
                {
                    ImageUser2 = Convert.ToString(drreq3["username"]);


                }
            }

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand ReqUser1 = new SqlCommand("spGetImageUser3", con);
                ReqUser1.CommandType = CommandType.StoredProcedure;

                SqlParameter ReqName3 = new SqlParameter("@name", Sender3);
                ReqUser1.Parameters.Add(ReqName3);



                con.Open();
                SqlDataReader drreq3;

                drreq3 = ReqUser1.ExecuteReader();

                if (drreq3.Read())
                {
                    ImageUser3 = Convert.ToString(drreq3["username"]);


                }
            }

            if (ImageUser1 != null)
            {
                ImageProf1.ImageUrl = "../ProfilePicHandler.ashx?uname=" + ImageUser1;

            }
            if (ImageUser2 != null)
            {
                ImageProf2.ImageUrl = "../ProfilePicHandler.ashx?uname=" + ImageUser2;
            }
            if (ImageUser3 != null)
            {
                ImageProf3.ImageUrl = "../ProfilePicHandler.ashx?uname=" + ImageUser3;
            }

            
            
            /////////////////////////////////////////////////////////////////////////////////////////////////////


            LabelSender1.Text = Sender1;
            LabelSender2.Text = Sender2;
            LabelSender3.Text = Sender3;
            LabelInvite1.Text = Invite1;
            LabelInvite2.Text = Invite2;
            LabelInvite3.Text = Invite3;
            LabelDivision1.Text = Division1;
            LabelDivision2.Text = Division2;
            LabelDivision3.Text = Division3;

            //if (LabelSender1.Text == "")
            //{
            //    LabelMsgNo.Text = "";

            //}
            //else if (LabelSender2.Text == "")
            //{
            //    LabelMsgNo.Text = "1";
            //}
            //else if (LabelSender3.Text == "")
            //{
            //    LabelMsgNo.Text = "2";
            //}
            //else
            //{
            //    LabelMsgNo.Text = "3";
            //}
        }


        protected void ButtonReply1_Click(object sender, EventArgs e)
        {
            ButtonCannot1.Visible = true;
            ButtonCan1.Visible = true;
        }
        protected void ButtonReply2_Click(object sender, EventArgs e)
        {
            ButtonCan2.Visible = true;
            ButtonCannot2.Visible = true;
        }
        protected void ButtonReply3_Click(object sender, EventArgs e)
        {
            ButtonCan3.Visible = true;
            ButtonCannot3.Visible = true;
        }
    }
}